package com.macro.mall.portal.domain;

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
import com.thoughtworks.xstream.annotations.XStreamOmitField;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
import me.chanjar.weixin.common.util.xml.XStreamInitializer;

@Data
@Builder(builderMethodName = "newBuilder")
@NoArgsConstructor
@AllArgsConstructor
@XStreamAlias("xml")
public class JhhWxPayNotifyResponse {

    @XStreamOmitField
    private static final transient String FAIL = "FAIL";
    @XStreamOmitField
    private static final transient String SUCCESS = "SUCCESS";

    @XStreamAlias("return_code")
    @XStreamConverter(value = XStreamCDataConverter.class)
    private String returnCode;

    @XStreamAlias("return_msg")
    @XStreamConverter(value = XStreamCDataConverter.class)
    private String returnMsg;

    @XStreamAlias("appid")
    @XStreamConverter(value = XStreamCDataConverter.class)
    private String appid;

    @XStreamAlias("mch_id")
    @XStreamConverter(value = XStreamCDataConverter.class)
    private String mchId;

    @XStreamAlias("nonce_str")
    @XStreamConverter(value = XStreamCDataConverter.class)
    private String nonceStr;

    @XStreamAlias("prepay_id")
    @XStreamConverter(value = XStreamCDataConverter.class)
    private String prepayId;

    @XStreamAlias("result_code")
    @XStreamConverter(value = XStreamCDataConverter.class)
    private String resultCode;

    @XStreamAlias("err_code_des")
    @XStreamConverter(value = XStreamCDataConverter.class)
    private String errCodeDes;

    @XStreamAlias("sign")
    @XStreamConverter(value = XStreamCDataConverter.class)
    private String sign;

    public static String toXml(JhhWxPayNotifyResponse response) {
        XStream xstream = XStreamInitializer.getInstance();
        xstream.autodetectAnnotations(true);
        return xstream.toXML(response).replace("\n", "").replace("  ", "");
    }
}
